const axios = require('axios')
// const Vue = require('vue')
const { Message } = require('element-ui');
const router = require('../../router/index');

module.exports={
    namespaced: true,
    state:{
    admStoresData:[],
    
    freezeStoresData:[]
    },
    mutations:{
        getStores(state,data){
            state.admStoresData=data
        },
        hideStores(state,daya){
            state.updateData=data
        },
        freezeStores(state,data){
            state.freezeStoresData=data
        }
    },
    actions:{
        async getStoresAsync(context){          
            const {data}=await axios.get('/stores/getStores',{params:{state:'正常'}})
            context.commit('getStores',data)
        },
        async freezeStoresAsync(context){
            const {data}=await axios.get('/stores/getStores',{params:{state:'冻结'}})
            context.commit('freezeStores',data)
        },
        
       
        async hideStoresAsync(context,order){
            if(order.state=='冻结'){
                order.state='正常'
            }else{
                order.state='冻结'
            }
            const {data}=await axios.post('/stores/updateStores',order)
            if(data&&order.state=='正常'){
                Message({
                    type: "success",
                    message: "该商家已恢复运营！"

                });
            }else{
                Message({
                    type: "success",
                    message: "该商家已被冻结！"
                });
            }
            context.dispatch('getStoresAsync')
            context.dispatch('freezeStoresAsync')



        }
    }

}